ifeq ($(yt_srctree),)
# 上面两层
yt_srctree := $(patsubst %/,%,$(dir $(CURDIR)))
yt_srctree := $(patsubst %/,%,$(dir $(yt_srctree)))

endif

BPF_BUILF_CONFIG_FILE ?= $(yt_srctree)/hacks/yt_build_bpf_yocto_libbpf_template_v1.mk
include ${BPF_BUILF_CONFIG_FILE}

BPF_SRCS := minimal.bpf.c
BPF_LOADER_SRC := minimal.c

BPF_HEADERS = $(BPF_SRCS:.bpf.c=.skel.h)
BPF_OBJ = $(BPF_SRCS:.bpf.c=.bpf.o)

BPF_LOADER := ${BPF_SRCS:.bpf.c=}

CLANG_BPF_SYS_INCLUDES = $(shell $(CLANG) -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')

${BPF_OBJ}:${BPF_SRCS}
	${CLANG} -target bpf ${CLANGFLAGS} ${CCINCLUDE} ${CLANG_BPF_SYS_INCLUDES} -c $< -o $@

${BPF_HEADERS}:${BPF_OBJ}
	${BPFTOOL} gen skeleton $< > $@

${BPF_LOADER}: ${BPF_LOADER_SRC} ${BPF_SRCS} ${BPF_HEADERS} 
	${CC} ${CCFLAGS} ${LOADINCLUDE} ${CLANG_BPF_SYS_INCLUDES} -o $@ $< ${liba_path}

build: ${BPF_LOADER}

clean:
	rm -rf ${BPF_HEADERS} ${BPF_OBJ} ${BPF_LOADER}

push:
	adb push ${BPF_LOADER} /data/
	adb shell sync
	adb shell "cd /data && scp ${BPF_LOADER}  root@192.168.100.1:~/"
all: clean build push

.DEFAULT_GOAL := all